home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1998 / MacHack 1998.toast / The Hacks! / The Crash Manager / "source" / cwindow.p < prev    next >
Encoding:
Text File  |  1998-06-20  |  4.1 KB  |  219 lines  |  [TEXT/CWIE]

  1. unit cwindow;
  2.  
  3. interface
  4.  
  5. uses
  6.     Appearance;
  7.  
  8. procedure DisplayWindow;
  9. procedure RemoveWindow;
  10. procedure DrawWindow(dState:ThemeDrawState);
  11. procedure DrawMainPane(dState:ThemeDrawState);
  12. procedure DrawSmallPic;
  13.  
  14. implementation
  15.  
  16. uses
  17.     Windows,
  18.     globals,
  19.     TextUtils,
  20.     Resources;
  21.     
  22. procedure DrawSmallPic;
  23. var
  24.     thePict:PicHandle;
  25.     r:Rect;
  26. begin
  27.     thePict:=GetPicture(1999+GetControlValue(gTypePopUp));
  28.     with r do begin
  29.         top:=70;
  30.         bottom:=top+150;
  31.         left:=LEFT_PANE_WIDTH+ (WINDOW_WIDTH-LEFT_PANE_WIDTH) div 2 - 100;
  32.         right:=left+200;
  33.     end;
  34.     DrawPicture(thePict,r);
  35.     ReleaseResource(Handle(thePict));
  36. end;
  37.     
  38. procedure DrawMainPane(dState:ThemeDrawState);
  39. var
  40.     r:Rect;
  41.     err:OSErr;
  42. begin
  43.     with r do begin
  44.         top:=-1;
  45.         left:=LEFT_PANE_WIDTH-1;
  46.         right:=WINDOW_WIDTH+1;
  47.         bottom:=WINDOW_HEIGHT+1;
  48.     end;
  49.     err:=DrawThemePlacard(r,dState);
  50.     
  51.     if gPaneState=PANE_BOMB then begin
  52.         HideControl(gFreqPopUp);
  53.         ShowControl(gTypePopUp);
  54.         ShowControl(gPreviewButton);
  55.     
  56.         TextSize(12);
  57.         TextFont(0);
  58.         MoveTo(LEFT_PANE_WIDTH+12,30);
  59.         DrawString('Crash Style:');
  60.         with r do begin 
  61.             top:=55;
  62.             bottom:=top+2;
  63.             left:=LEFT_PANE_WIDTH+12;
  64.             right:=WINDOW_WIDTH-12;
  65.         end;
  66.         err:=DrawThemeSeparator(r,dState);
  67.         DrawSmallPic;
  68.     end;
  69.     
  70.     if gPaneState=PANE_CLUSTER then begin
  71.         HideControl(gTypePopUp);
  72.         HideControl(gPreviewButton);
  73.         ShowControl(gFreqPopUp);
  74.         TextSize(12);
  75.         TextFont(0);
  76.         MoveTo(LEFT_PANE_WIDTH+12,30);
  77.         DrawString('Crash Frequency:');
  78.     end;
  79.     
  80.     DrawControls(gMainWindow);
  81. end;
  82.     
  83. procedure DrawWindow(dState:ThemeDrawState);
  84. var
  85.     err:OSErr;
  86.     r:Rect;
  87.     s:Str32;
  88. begin
  89.     with r do begin
  90.         top:=-1;
  91.         left:=-1;
  92.         right:=LEFT_PANE_WIDTH;
  93.         bottom:=WINDOW_HEIGHT+1;
  94.     end;
  95.     err:=DrawThemePlacard(r,dState);
  96.     
  97.     TextSize(10);
  98.     TextFont(1);
  99.     GetIndString(s,1000,1);
  100.     MoveTo(BUTTON_LEFT+(BUTTON_WIDTH div 2) -(StringWidth(s) div 2),BUTTON_TOP+BUTTON_HEIGHT+11);
  101.     DrawString(s);
  102.     GetIndString(s,1000,2);
  103.     MoveTo(BUTTON_LEFT+(BUTTON_WIDTH div 2) -(StringWidth(s) div 2),BUTTON_TOP+BUTTON_HEIGHT*2+BUTTON_SPACE+11);
  104.     DrawString(s);
  105.     
  106.     DrawMainPane(dState);
  107. end;
  108.  
  109. procedure DisplayWindow;
  110. var
  111.     tRect:Rect;
  112. begin
  113.     with tRect do begin
  114.         top:=50;
  115.         bottom:=top+WINDOW_HEIGHT;
  116.         left:=50;
  117.         right:=left+WINDOW_WIDTH;
  118.     end;
  119.     gMainWindow:=NewCWindow(nil,
  120.                             tRect,
  121.                             'Crash',
  122.                             false,
  123.                             kWindowDocumentProc,
  124.                             WindowPtr(-1),
  125.                             true,
  126.                             0);
  127.     SetPort(gMainWindow);
  128.     with tRect do begin
  129.         top:=BUTTON_TOP;
  130.         bottom:=BUTTON_TOP+BUTTON_HEIGHT;
  131.         left:=BUTTON_LEFT;
  132.         right:=BUTTON_LEFT+BUTTON_WIDTH;
  133.     end;
  134.     gBombButton:=NewControl(gMainWindow,
  135.                             tRect,
  136.                             '',
  137.                             true,
  138.                             0,
  139.                             kControlContentCIconRes+kControlBehaviorSticky,
  140.                             1000,
  141.                             kControlBevelButtonNormalBevelProc,
  142.                             0);
  143.     SetControlValue(gBombButton,1);
  144.     with tRect do begin
  145.         top:=BUTTON_TOP+BUTTON_HEIGHT+BUTTON_SPACE;
  146.         bottom:=top+BUTTON_HEIGHT;
  147.         left:=BUTTON_LEFT;
  148.         right:=BUTTON_LEFT+BUTTON_WIDTH;
  149.     end;
  150.     gClusterButton:=NewControl(gMainWindow,
  151.                             tRect,
  152.                             '',
  153.                             true,
  154.                             0,
  155.                             kControlContentCIconRes+kControlBehaviorSticky,
  156.                             1001,
  157.                             kControlBevelButtonNormalBevelProc,
  158.                             0);
  159.     with tRect do begin
  160.         top:=18;
  161.         bottom:=34;
  162.         left:=170;
  163.         right:=370;
  164.     end;
  165.     gTypePopUp:=NewControl(gMainWindow,
  166.                             tRect,
  167.                             '',
  168.                             true,
  169.                             0,
  170.                             2000,
  171.                             0,
  172.                             kControlPopupButtonProc,
  173.                             0);
  174.     SetControlValue(gTypePopUp,gThePrefs.style);
  175.                             
  176.     with tRect do begin
  177.         top:=230;
  178.         bottom:=top+20;
  179.         right:=WINDOW_WIDTH-12;
  180.         left:=right-90;
  181.     end;
  182.     gPreviewButton:=NewControl(gMainWindow,
  183.                             tRect,
  184.                             'Preview',
  185.                             true,
  186.                             0,
  187.                             1,
  188.                             0,
  189.                             kControlPushButtonProc,
  190.                             0);
  191.     with tRect do begin
  192.         top:=18;
  193.         bottom:=34;
  194.         left:=205;
  195.         right:=370;
  196.     end;
  197.     gFreqPopUp:=NewControl(gMainWindow,
  198.                             tRect,
  199.                             '',
  200.                             false,
  201.                             0,
  202.                             2001,
  203.                             0,
  204.                             kControlPopupButtonProc,
  205.                             0);
  206.     SetControlValue(gFreqPopUp,gThePrefs.frequency);
  207.     
  208.     ShowWindow(gMainWindow);
  209.     DrawWindow(kThemeStateActive);
  210. end;
  211.  
  212. procedure RemoveWindow;
  213. begin
  214.     gThePrefs.style:=GetControlValue(gTypePopUp);
  215.     gThePrefs.frequency:=GetControlValue(gFreqPopUp);
  216.     DisposeWindow(gMainWindow);
  217. end;
  218.  
  219. end.